package com.mall.manager.sdkclick.service;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * @按钮点击统计
 * @author liugb
 * @2016 7 13
 */
@Service
public class SdkClickService {
	@Resource
    private JdbcTemplate jdbcTemplate;
	
	//日志信息
	private Logger logger = LoggerFactory.getLogger(SdkClickService.class);
	/**
	 * @按点击类型显示柱状图
	 * @param request
	 * @return
	 */
	public List<Map<String, Object>> manager_sdkClick_list(Map<String, Object> paraMap1,String time) {
		try {
			String data_type = MapUtils.getString(paraMap1, "data_type");
			String sql = "";
			List<Map<String,Object>> rs = null;
			if(data_type == null || data_type.isEmpty()){
				sql = "select * from db_processing.t_sdk_click where 1=1 and date_format(create_time,'%Y-%m-%d') = '" + time +"'";
				rs = jdbcTemplate.queryForList(sql);
			}else {
				sql = " select * from db_processing.t_sdk_click where 1=1 and  data_type = ? and date_format(create_time,'%Y-%m-%d') = '" + time +"'";
				rs = jdbcTemplate.queryForList(sql, data_type);
			}	
			return rs;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			logger.info(e.getMessage());
			return null;
		}
	}
	
	/**
     * @点击类型添加数据
     * @param paraMap
     * @return
     */
	public int manager_insert_sdkclick(Map<String, Object> paraMap) {
		String click_count = MapUtils.getString(paraMap, "click_count");
		String data_type = MapUtils.getString(paraMap, "data_type");
		try {
			String sql="insert into t_sdk_click(id,click_count,data_type,create_time,udpate_time) values(?,?,?,now(),now())";
			int update = jdbcTemplate.update(sql,click_count,data_type);
			return update;
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}
}
